package tmp;

public class Rational implements Cloneable{

	private int numerator, denominator;

	public Rational(int num, int denom) {
		numerator = num;
		denominator = denom;
	}

	public static void main(String[] args) {
		Rational r = new Rational(2, 3);
		System.out.println(r);
		System.out.println("comparing with String: "+r.equals(new String()));
		System.out.println("comparing with NULL: "+r.equals(null));
		System.out.println("hashCode: "+r.hashCode() + " " + r.hashCode());
		try {
			System.out.println(r.clone());
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj != null && this.getClass() == obj.getClass()) {
			if (numerator == ((Rational) obj).numerator
					&& denominator == ((Rational) obj).numerator)
				return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return numerator + "/" + denominator;
	}

	@Override
	public Rational clone() throws CloneNotSupportedException {
		return (Rational)super.clone();
/**		return new Rational(numerator, denominator);
		tozhe dopuskaetsa, no pridetsa perepisyvat' zanovo
		esli izmenitsa bazovyj klass. tak zhe, ne vsegda izvestno kak opisan base class
*/
	}
}
